<!doctype html>



  


<html class="theme-next muse use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  
    
      
    

    
  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Microsoft YaHei:300,300italic,400,400italic,700,700italic|consolas:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="模块化,SeaJs,RequireJS," />








  <link rel="shortcut icon" type="image/x-icon" href="http://ofy7k3v4s.bkt.clouddn.com/mylogo.png?v=5.0.2" />






<meta name="description" content="&amp;#x5386;&amp;#x53F2;&amp;#x4E0A;&amp;#xFF0C;JavaScript&amp;#x4E00;&amp;#x76F4;&amp;#x6CA1;&amp;#x6709;&amp;#x6A21;&amp;#x5757;&amp;#xFF08;module&amp;#xFF09;&amp;#x4F53;&amp;#x7CFB;&amp;#xFF0C;&amp;#x65E0;&amp;#x6CD5;&amp;#x5C06;&amp;#x4E00;&amp;#x4E2A;&amp;#x5927;&amp;#x7A0B;&amp;#x5E8F;">
<meta property="og:type" content="article">
<meta property="og:title" content="js 的模块化">
<meta property="og:url" content="https://hongqinma.github.io/2015/05/11/25-js-的模块化/index.html">
<meta property="og:site_name" content="HongqinMa' Blog">
<meta property="og:description" content="&amp;#x5386;&amp;#x53F2;&amp;#x4E0A;&amp;#xFF0C;JavaScript&amp;#x4E00;&amp;#x76F4;&amp;#x6CA1;&amp;#x6709;&amp;#x6A21;&amp;#x5757;&amp;#xFF08;module&amp;#xFF09;&amp;#x4F53;&amp;#x7CFB;&amp;#xFF0C;&amp;#x65E0;&amp;#x6CD5;&amp;#x5C06;&amp;#x4E00;&amp;#x4E2A;&amp;#x5927;&amp;#x7A0B;&amp;#x5E8F;">
<meta property="og:updated_time" content="2016-12-02T03:34:07.251Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="js 的模块化">
<meta name="twitter:description" content="&amp;#x5386;&amp;#x53F2;&amp;#x4E0A;&amp;#xFF0C;JavaScript&amp;#x4E00;&amp;#x76F4;&amp;#x6CA1;&amp;#x6709;&amp;#x6A21;&amp;#x5757;&amp;#xFF08;module&amp;#xFF09;&amp;#x4F53;&amp;#x7CFB;&amp;#xFF0C;&amp;#x65E0;&amp;#x6CD5;&amp;#x5C06;&amp;#x4E00;&amp;#x4E2A;&amp;#x5927;&amp;#x7A0B;&amp;#x5E8F;">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '6347850919329138000',
      author: 'Hiraku'
    }
  };
</script>




  <link rel="canonical" href="https://hongqinma.github.io/2015/05/11/25-js-的模块化/"/>


  <title> js 的模块化 | HongqinMa' Blog </title>
</head>

<body itemscope itemtype="//schema.org/WebPage" lang="en">

  



  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?10010323";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>








  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="//schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta custom-logo">
  
    <div class="site-meta-headline">
      <a>
        <img class="custom-logo-image" src="http://ofy7k3v4s.bkt.clouddn.com/photo.jpg"
             alt="HongqinMa' Blog"/>
      </a>
    </div>
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">HongqinMa' Blog</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">Spell at all costs， to rush you in the future。</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            Categories
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            About
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            Tags
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="//schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                js 的模块化
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">Posted on</span>
            <time itemprop="dateCreated" datetime="2015-05-11T18:40:02+08:00" content="2015-05-11">
              2015-05-11
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">In</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/JavaScript/" itemprop="url" rel="index">
                    <span itemprop="name">JavaScript</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/2015/05/11/25-js-的模块化/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2015/05/11/25-js-的模块化/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          

          
              &nbsp; | &nbsp;
              <span class="page-pv"><i class="fa fa-file-o"></i>
              <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>
              </span>
          

          
            <span id="busuanzi_container_page_pv">  <span id="busuanzi_value_page_pv"></span> Views</span>
          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>&#x5386;&#x53F2;&#x4E0A;&#xFF0C;JavaScript&#x4E00;&#x76F4;&#x6CA1;&#x6709;&#x6A21;&#x5757;&#xFF08;module&#xFF09;&#x4F53;&#x7CFB;&#xFF0C;&#x65E0;&#x6CD5;&#x5C06;&#x4E00;&#x4E2A;&#x5927;&#x7A0B;&#x5E8F;&#x62C6;&#x5206;&#x6210;&#x4E92;&#x76F8;&#x4F9D;&#x8D56;&#x7684;&#x5C0F;&#x6587;&#x4EF6;&#xFF0C;&#x518D;&#x7528;&#x7B80;&#x5355;&#x7684;&#x65B9;&#x6CD5;&#x62FC;&#x88C5;&#x8D77;&#x6765;&#x3002;&#x5176;&#x4ED6;&#x8BED;&#x8A00;&#x90FD;&#x6709;&#x8FD9;&#x9879;&#x529F;&#x80FD;&#xFF0C;&#x6BD4;&#x5982; Ruby &#x7684; <code>require</code>&#x3001;Python &#x7684; <code>import</code> &#xFF0C;&#x751A;&#x81F3;&#x5C31;&#x8FDE; CSS &#x90FD;&#x6709; <code>@import</code> &#xFF0C;c &#x8BED;&#x8A00;&#x4E2D;&#x7684; <code>include</code>&#xFF0C;&#x4F46;&#x662F; JavaScript &#x4EFB;&#x4F55;&#x8FD9;&#x65B9;&#x9762;&#x7684;&#x652F;&#x6301;&#x90FD;&#x6CA1;&#x6709;&#xFF0C;&#x8FD9;&#x5BF9;&#x5F00;&#x53D1;&#x5927;&#x578B;&#x7684;&#x3001;&#x590D;&#x6742;&#x7684;&#x9879;&#x76EE;&#x5F62;&#x6210;&#x4E86;&#x5DE8;&#x5927;&#x969C;&#x788D;&#x3002;</p>
<h2 id="JavaScript-&#x6A21;&#x5757;&#x5316;&#x5F00;&#x53D1;"><a href="#JavaScript-&#x6A21;&#x5757;&#x5316;&#x5F00;&#x53D1;" class="headerlink" title="JavaScript &#x6A21;&#x5757;&#x5316;&#x5F00;&#x53D1;"></a>JavaScript &#x6A21;&#x5757;&#x5316;&#x5F00;&#x53D1;</h2><h2 id="&#x6A21;&#x5757;&#x5316;&#x4ECB;&#x7ECD;"><a href="#&#x6A21;&#x5757;&#x5316;&#x4ECB;&#x7ECD;" class="headerlink" title="&#x6A21;&#x5757;&#x5316;&#x4ECB;&#x7ECD;"></a>&#x6A21;&#x5757;&#x5316;&#x4ECB;&#x7ECD;</h2><p><strong>&#x5F53;&#x4F60;&#x7684;&#x7F51;&#x7AD9;&#x5F00;&#x53D1;&#x8D8A;&#x6765;&#x8D8A;&#x590D;&#x6742;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4F1A;&#x7ECF;&#x5E38;&#x9047;&#x5230;&#x4EC0;&#x4E48;&#x95EE;&#x9898;&#xFF1F;</strong></p>
<p>1&#x3001;&#x6A21;&#x5757;&#x5316;&#x601D;&#x60F3;&#x53EF;&#x4EE5;&#x8BA9;&#x5F00;&#x53D1;&#x66F4;&#x9AD8;&#x6548;<br>2&#x3001;&#x5B9E;&#x73B0;&#x6A21;&#x5757;&#x5316;&#x9700;&#x8981;&#x89E3;&#x51B3;&#x4E00;&#x4E2A;&#x4EFB;&#x52A1;&#xFF0C;&#x8FD9;&#x4E2A;&#x4EFB;&#x52A1;&#x5C31;&#x662F;&#x4F9D;&#x8D56;&#x5173;&#x7CFB;<br>3&#x3001;&#x6D4F;&#x89C8;&#x5668;&#x7AEF; js &#x662F;&#x5929;&#x7136;&#x4E0D;&#x80FD;&#x5B9E;&#x73B0;&#x6A21;&#x5757;<br>4&#x3001;&#x6709;&#x4E00;&#x4E9B;&#x5E93;&#x5F25;&#x8865;&#x4E86;&#x6D4F;&#x89C8;&#x5668;&#x7AEF; js &#x7684;&#x4E00;&#x4E9B;&#x7F3A;&#x9677;&#xFF0C;&#x5B9E;&#x73B0;&#x4E86;&#x6A21;&#x5757;&#x5316;&#x5E76;&#x89E3;&#x51B3;&#x4E86;&#x4F9D;&#x8D56;&#x5173;&#x7CFB;</p>
<blockquote>
<p>&#x5C06;&#x8FD9;&#x79CD;&#x5E93;&#x79F0;&#x4E3A;&#x6A21;&#x5757;&#x52A0;&#x8F7D;&#x5668;&#xFF0C;RequireJS&#x3001;SeaJS</p>
</blockquote>
<p>&#x8FD9;&#x4E9B;&#x6A21;&#x5757;&#x52A0;&#x8F7D;&#x5668;&#x5B9A;&#x4E49;&#x4E86;&#x81EA;&#x5DF1;&#x7684;&#x89C4;&#x8303;&#xFF0C;&#x5FC5;&#x987B;&#x5C0A;&#x65E9;&#x8FD9;&#x4E9B;&#x89C4;&#x8303;&#x624D;&#x80FD;&#x6B63;&#x5E38;&#x5DE5;&#x4F5C;&#x3002;</p>
<p>&#x4EE5; SeaJS &#x4E3A;&#x4F8B;&#x5B50;&#xFF1A;</p>
<ul>
<li>&#x901A;&#x8FC7; define() &#x65B9;&#x6CD5;&#x6765;&#x5B9A;&#x4E49;&#x6A21;&#x5757;</li>
<li>&#x901A;&#x8FC7; use() &#x65B9;&#x6CD5;&#x6765;&#x52A0;&#x8F7D;/&#x6267;&#x884C;&#x6A21;&#x5757;</li>
<li>&#x901A;&#x8FC7; require() &#x65B9;&#x6CD5;&#x6765;&#x5F15;&#x5165;&#x6A21;&#x5757;</li>
<li>&#x901A;&#x8FC7; exports/module.exports &#x66B4;&#x6F0F;&#x6A21;&#x5757;&#x529F;&#x80FD;</li>
</ul>
<p><code>Sea.js</code> &#x53EF;&#x4EE5;&#x89E3;&#x51B3;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x6C61;&#x67D3;&#x3001;&#x6587;&#x4EF6;&#x4F9D;&#x8D56;&#x7684;&#x95EE;&#x9898;&#x3002;</p>
<ul>
<li>&#x6A21;&#x5757;&#x7684;&#x4F5C;&#x7528;&#x5C31;&#x662F;&#xFF1A;&#x79C1;&#x6709;&#x7A7A;&#x95F4;</li>
<li><p>&#x53EF;&#x4EE5;&#x52A0;&#x8F7D;&#xFF0C;&#x53EF;&#x4EE5;&#x5BFC;&#x51FA;</p>
</li>
<li><p>&#x4EC0;&#x4E48;&#x662F;&#x6A21;&#x5757;&#x5316;</p>
<ul>
<li>&#x6A21;&#x5757;&#x5316;&#x662F;&#x6307;&#x89E3;&#x51B3;&#x4E00;&#x4E2A;&#x590D;&#x6742;&#x95EE;&#x9898;&#x65F6;&#x81EA;&#x9876;&#x5411;&#x4E0B;&#x9010;&#x5C42;&#x628A;&#x7CFB;&#x7EDF;&#x5212;&#x5206;&#x6210;&#x82E5;&#x5E72;&#x6A21;&#x5757;&#x7684;&#x8FC7;&#x7A0B;&#xFF0C;&#x6709;&#x591A;&#x79CD;&#x5C5E;&#x6027;&#xFF0C;&#x5206;&#x522B;&#x53CD;&#x6620;&#x5176;&#x5185;&#x90E8;&#x7279;&#x6027;&#x3002;</li>
<li>&#x89E3;&#x51B3;&#x590D;&#x6742;&#x95EE;&#x9898;&#x7684;&#x4E00;&#x79CD;&#x65B9;&#x5F0F;&#x800C;&#x5DF2;</li>
<li>&#x7535;&#x8111;&#xFF1A;CPU&#x3001;&#x4E3B;&#x677F;&#x3001;&#x663E;&#x793A;&#x5668;&#x3001;&#x5185;&#x5B58;&#x3001;&#x786C;&#x76D8;&#x3001;&#x8F93;&#x5165;&#x4E0E;&#x8F93;&#x51FA;&#x8BBE;&#x5907;</li>
</ul>
</li>
<li><p>&#x4F7F;&#x7528;&#x6A21;&#x5757;&#x5316;&#x5F00;&#x53D1;&#x7684;&#x65B9;&#x5F0F;&#x5E26;&#x6765;&#x7684;&#x597D;&#x5904;</p>
<ul>
<li>&#x751F;&#x4EA7;&#x6548;&#x7387;&#x9AD8;</li>
<li>&#x53EF;&#x7EF4;&#x62A4;&#x6027;&#x9AD8;</li>
</ul>
</li>
</ul>
<hr>
<h2 id="&#x6A21;&#x5757;&#x5316;&#x5F00;&#x53D1;&#x6F14;&#x53D8;"><a href="#&#x6A21;&#x5757;&#x5316;&#x5F00;&#x53D1;&#x6F14;&#x53D8;" class="headerlink" title="&#x6A21;&#x5757;&#x5316;&#x5F00;&#x53D1;&#x6F14;&#x53D8;"></a>&#x6A21;&#x5757;&#x5316;&#x5F00;&#x53D1;&#x6F14;&#x53D8;</h2><h3 id="&#x5168;&#x5C40;&#x51FD;&#x6570;"><a href="#&#x5168;&#x5C40;&#x51FD;&#x6570;" class="headerlink" title="&#x5168;&#x5C40;&#x51FD;&#x6570;"></a>&#x5168;&#x5C40;&#x51FD;&#x6570;</h3><ul>
<li>&#x6C61;&#x67D3;&#x4E86;&#x5168;&#x5C40;&#x53D8;&#x91CF;</li>
<li>&#x6A21;&#x5757;&#x6210;&#x5458;&#x4E4B;&#x95F4;&#x770B;&#x4E0D;&#x51FA;&#x76F4;&#x63A5;&#x5173;&#x7CFB;</li>
</ul>
<h3 id="&#x547D;&#x540D;&#x7A7A;&#x95F4;"><a href="#&#x547D;&#x540D;&#x7A7A;&#x95F4;" class="headerlink" title="&#x547D;&#x540D;&#x7A7A;&#x95F4;"></a>&#x547D;&#x540D;&#x7A7A;&#x95F4;</h3><ul>
<li>&#x7406;&#x8BBA;&#x610F;&#x4E49;&#x4E0A;&#x51CF;&#x5C11;&#x4E86;&#x53D8;&#x91CF;&#x51B2;&#x7A81;</li>
<li>&#x7F3A;&#x70B9;1&#xFF1A;&#x66B4;&#x9732;&#x4E86;&#x6A21;&#x5757;&#x4E2D;&#x6240;&#x6709;&#x7684;&#x6210;&#x5458;&#xFF0C;&#x5185;&#x90E8;&#x72B6;&#x6001;&#x53EF;&#x4EE5;&#x88AB;&#x5916;&#x90E8;&#x6539;&#x5199;&#xFF0C;&#x4E0D;&#x5B89;&#x5168;</li>
<li>&#x7F3A;&#x70B9;2&#xFF1A;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x4F1A;&#x8D8A;&#x6765;&#x8D8A;&#x957F;</li>
</ul>
<h3 id="&#x79C1;&#x6709;&#x7A7A;&#x95F4;"><a href="#&#x79C1;&#x6709;&#x7A7A;&#x95F4;" class="headerlink" title="&#x79C1;&#x6709;&#x7A7A;&#x95F4;"></a>&#x79C1;&#x6709;&#x7A7A;&#x95F4;</h3><ul>
<li>&#x79C1;&#x6709;&#x7A7A;&#x95F4;&#x7684;&#x53D8;&#x91CF;&#x548C;&#x51FD;&#x6570;&#x4E0D;&#x4F1A;&#x5F71;&#x54CD;&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;</li>
<li>&#x516C;&#x5F00;&#x516C;&#x6709;&#x65B9;&#x6CD5;&#xFF0C;&#x9690;&#x85CF;&#x79C1;&#x6709;&#x5C5E;&#x6027;</li>
</ul>
<h3 id="&#x6A21;&#x5757;&#x7684;&#x7EF4;&#x62A4;&#x548C;&#x6269;&#x5C55;"><a href="#&#x6A21;&#x5757;&#x7684;&#x7EF4;&#x62A4;&#x548C;&#x6269;&#x5C55;" class="headerlink" title="&#x6A21;&#x5757;&#x7684;&#x7EF4;&#x62A4;&#x548C;&#x6269;&#x5C55;"></a>&#x6A21;&#x5757;&#x7684;&#x7EF4;&#x62A4;&#x548C;&#x6269;&#x5C55;</h3><ul>
<li>&#x5F00;&#x95ED;&#x539F;&#x5219;</li>
<li>&#x53EF;&#x7EF4;&#x62A4;&#x6027;&#x597D;</li>
</ul>
<h3 id="&#x6A21;&#x5757;&#x7684;&#x7B2C;&#x4E09;&#x65B9;&#x4F9D;&#x8D56;"><a href="#&#x6A21;&#x5757;&#x7684;&#x7B2C;&#x4E09;&#x65B9;&#x4F9D;&#x8D56;" class="headerlink" title="&#x6A21;&#x5757;&#x7684;&#x7B2C;&#x4E09;&#x65B9;&#x4F9D;&#x8D56;"></a>&#x6A21;&#x5757;&#x7684;&#x7B2C;&#x4E09;&#x65B9;&#x4F9D;&#x8D56;</h3><ul>
<li>&#x4FDD;&#x8BC1;&#x6A21;&#x5757;&#x7684;&#x72EC;&#x7ACB;&#x6027;</li>
<li>&#x6A21;&#x5757;&#x4E4B;&#x95F4;&#x7684;&#x4F9D;&#x8D56;&#x5173;&#x7CFB;&#x53D8;&#x5F97;&#x660E;&#x663E;</li>
</ul>
<h3 id="&#x603B;&#x7ED3;"><a href="#&#x603B;&#x7ED3;" class="headerlink" title="&#x603B;&#x7ED3;"></a>&#x603B;&#x7ED3;</h3><p>&#x4EE5;&#x540E;&#x5982;&#x679C;&#x4E0D;&#x4F7F;&#x7528;&#x7B2C;&#x4E09;&#x65B9;&#x89C4;&#x8303;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x5982;&#x679C;&#x5199;&#x6A21;&#x5757;&#x53EF;&#x4EE5;&#x91C7;&#x7528;&#x4E0B;&#x9762;&#x8FD9;&#x79CD;&#x65B9;&#x5F0F;&#xFF1A;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line"><span class="comment">// 1. &#x5206;&#x53F7;&#x662F;&#x4EC0;&#x4E48;&#x610F;&#x601D;</span></div><div class="line"><span class="comment">// 2. &#x4E3A;&#x4EC0;&#x4E48;&#x8981;&#x7ED9;&#x4F60;&#x7684;&#x4EE3;&#x7801;&#x52A0;&#x4E00;&#x4E2A;&#x533F;&#x540D;&#x81EA;&#x6267;&#x884C;&#x51FD;&#x6570;</span></div><div class="line"><span class="comment">// 3. &#x4E3A;&#x4EC0;&#x4E48;&#x8981;&#x628A;&#x4F7F;&#x7528;&#x7684;&#x4F9D;&#x8D56;&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#x4F20;&#x9012;&#x8FDB;&#x6765;</span></div><div class="line">;(<span class="function"><span class="keyword">function</span> (<span class="params">&#x5F62;&#x53C2;&#x6A21;&#x5757;&#x540D;, &#x4F9D;&#x8D56;&#x9879;, &#x4F9D;&#x8D56;&#x9879;</span>) </span>{</div><div class="line">  <span class="comment">// &#x901A;&#x8FC7; &#x5F62;&#x53C2;&#x6A21;&#x5757;&#x540D; &#x4FEE;&#x6539;&#x6A21;&#x5757;</span></div><div class="line">  <span class="comment">// &#x5982;&#x679C;&#x9700;&#x8981;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x7ED9; window &#x5BF9;&#x8C61;&#x6302;&#x8F7D;&#x5C5E;&#x6027;&#x5BF9;&#x5916;&#x66B4;&#x9732;&#x5185;&#x90E8;&#x6210;&#x5458;</span></div><div class="line">  <span class="built_in">window</span>.&#x6A21;&#x5757;&#x540D; = &#x5F62;&#x53C2;&#x6A21;&#x5757;&#x540D;</div><div class="line">})(<span class="built_in">window</span>.&#x6A21;&#x5757;&#x540D; || {}, &#x4F9D;&#x8D56;&#x9879;, &#x4F9D;&#x8D56;&#x9879;)</div></pre></td></tr></table></figure>
<hr>
<h2 id="&#x6A21;&#x5757;&#x5316;&#x89C4;&#x8303;"><a href="#&#x6A21;&#x5757;&#x5316;&#x89C4;&#x8303;" class="headerlink" title="&#x6A21;&#x5757;&#x5316;&#x89C4;&#x8303;"></a>&#x6A21;&#x5757;&#x5316;&#x89C4;&#x8303;</h2><h3 id="&#x6A21;&#x5757;&#x7CFB;&#x7EDF;&#x7406;&#x89E3;"><a href="#&#x6A21;&#x5757;&#x7CFB;&#x7EDF;&#x7406;&#x89E3;" class="headerlink" title="&#x6A21;&#x5757;&#x7CFB;&#x7EDF;&#x7406;&#x89E3;"></a>&#x6A21;&#x5757;&#x7CFB;&#x7EDF;&#x7406;&#x89E3;</h3><p>&#x81EA;&#x7136;&#x754C;&#x751F;&#x6001;&#x7CFB;&#x7EDF;&#x3001;&#x8BA1;&#x7B97;&#x673A;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x3001;&#x8F6F;&#x4EF6;&#x529E;&#x516C;&#x7CFB;&#x7EDF;&#xFF0C;&#x8FD8;&#x6709;&#x6559;&#x80B2;&#x7CFB;&#x7EDF;&#x3001;&#x91D1;&#x878D;&#x7CFB;&#x7EDF;&#x3001;&#x7F51;&#x7EDC;&#x7CFB;&#x7EDF;&#x3001;&#x7406;&#x8BBA;&#x7CFB;&#x7EDF;&#x7B49;&#x7B49;&#x3002;&#x7A76;&#x7ADF;&#x4EC0;&#x4E48;&#x662F;&#x7CFB;&#x7EDF;&#x5462;&#xFF1F;</p>
<p>&#x7B80;&#x5355;&#x6765;&#x8BF4;&#xFF0C;&#x7CFB;&#x7EDF;&#x6709;&#x4E24;&#x4E2A;&#x57FA;&#x672C;&#x7279;&#x6027;&#xFF1A;</p>
<ol>
<li>&#x7CFB;&#x7EDF;&#x7531;&#x4E2A;&#x4F53;&#x7EC4;&#x6210;</li>
<li>&#x4E2A;&#x4F53;&#x4E4B;&#x95F4;&#x6709;&#x5173;&#x8054;&#xFF0C;&#x6309;&#x7167;&#x89C4;&#x5219;&#x534F;&#x540C;&#x5B8C;&#x6210;&#x4EFB;&#x52A1;</li>
</ol>
<p>&#x7CFB;&#x7EDF;&#x4E4B;&#x95F4;&#x7684;&#x4E2A;&#x4F53;&#x53EF;&#x4EE5;&#x6210;&#x4E3A;&#x7CFB;&#x7EDF;&#x6210;&#x5458;&#xFF0C;&#x8981;&#x6784;&#x5EFA;&#x4E00;&#x4E2A;&#x7CFB;&#x7EDF;&#xFF0C;&#x6700;&#x57FA;&#x672C;&#x7684;&#x5C42;&#x9762;&#x9700;&#x8981;&#x505A;&#x4E24;&#x4EF6;&#x4E8B;&#xFF1A;</p>
<ol>
<li><strong>&#x5B9A;&#x4E49;&#x7CFB;&#x7EDF;&#x6210;&#x5458;</strong>&#xFF1A;&#x786E;&#x5B9A;&#x6210;&#x5458;&#x662F;&#x4EC0;&#x4E48;<ul>
<li>&#x6A21;&#x5757;&#x662F;&#x4E00;&#x4E2A; JavaScript &#x6587;&#x4EF6;</li>
<li>&#x6BCF;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x90FD;&#x4F7F;&#x7528; <code>define</code> &#x51FD;&#x6570;&#x53BB;&#x5B9A;&#x4E49;</li>
</ul>
</li>
<li><strong>&#x7EA6;&#x5B9A;&#x7CFB;&#x7EDF;&#x901A;&#x8BAF;</strong>&#xFF1A;&#x786E;&#x5B9A;&#x6210;&#x5458;&#x4E4B;&#x95F4;&#x5982;&#x4F55;&#x4EA4;&#x4E92;&#xFF0C;&#x9075;&#x5FAA;&#x7684;&#x89C4;&#x5219;&#x662F;&#x4EC0;&#x4E48;<ul>
<li>&#x4E00;&#x4E2A; SeaJS &#x6A21;&#x5757;&#x9ED8;&#x8BA4;&#x5C31;&#x662F;&#x79C1;&#x6709;&#x4F5C;&#x7528;&#x57DF;</li>
<li>&#x5982;&#x679C;&#x60F3;&#x8981;&#x88AB;&#x5916;&#x90E8;&#x6587;&#x4EF6;&#x6A21;&#x5757;&#x6240;&#x8BBF;&#x95EE;&#xFF0C;&#x5C31;&#x5FC5;&#x987B;&#x628A;&#x8981;&#x516C;&#x5F00;&#x7684;&#x5C5E;&#x6027;&#x6302;&#x8F7D;&#x7ED9; <code>module.exports</code> &#x5BF9;&#x8C61;&#x63A5;&#x53E3;</li>
<li>&#x4F7F;&#x7528; <code>require</code> &#x51FD;&#x6570;&#x53EF;&#x4EE5;&#x52A0;&#x8F7D;&#x4E00;&#x4E2A;&#x6307;&#x5B9A;&#x7684;&#x6A21;&#x5757;&#xFF0C;&#x5F97;&#x5230;&#x8BE5;&#x6A21;&#x5757;&#x4EE3;&#x7801;&#x4E2D;&#x66B4;&#x9732;&#x7684;&#x63A5;&#x53E3;&#x5BF9;&#x8C61;</li>
</ul>
</li>
<li>&#x5982;&#x4F55;&#x542F;&#x52A8;&#x6574;&#x4E2A;&#x6A21;&#x5757;&#x7CFB;&#x7EDF;<ul>
<li>&#x5728; html &#x9875;&#x9762;&#x4E2D;&#x4F7F;&#x7528; <code>seajs.use()</code> &#x65B9;&#x6CD5;&#xFF0C;&#x6307;&#x5B9A;&#x4E00;&#x4E2A;&#x5165;&#x53E3;&#x6587;&#x4EF6;&#x6A21;&#x5757;</li>
</ul>
</li>
</ol>
<p>Sea.js &#x662F;&#x4E00;&#x4E2A;&#x9002;&#x7528;&#x4E8E; Web &#x6D4F;&#x89C8;&#x5668;&#x7AEF;&#x7684;&#x6A21;&#x5757;&#x52A0;&#x8F7D;&#x5668;&#x3002;&#x5728; Sea.js &#x91CC;&#xFF0C;&#x4E00;&#x5207;&#x7686;&#x662F;&#x6A21;&#x5757;&#xFF0C;&#x6240;&#x6709;&#x6A21;&#x5757;&#x534F;&#x540C;&#x6784;&#x5EFA;&#x6210;&#x6A21;&#x5757;&#x7CFB;&#x7EDF;&#x3002;Sea.js &#x9996;&#x8981;&#x8981;&#x89E3;&#x51B3;&#x7684;&#x662F;&#x6A21;&#x5757;&#x7CFB;&#x7EDF;&#x7684;&#x57FA;&#x672C;&#x95EE;&#x9898;&#xFF1A;</p>
<ol>
<li>&#x6A21;&#x5757;&#x662F;&#x4EC0;&#x4E48;&#xFF1F;</li>
<li>&#x6A21;&#x5757;&#x4E4B;&#x95F4;&#x5982;&#x4F55;&#x4EA4;&#x4E92;&#xFF1F;</li>
</ol>
<p>&#x5728;&#x524D;&#x7AEF;&#x5F00;&#x53D1;&#x9886;&#x57DF;&#xFF0C;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#xFF0C;&#x53EF;&#x4EE5;&#x662F;JS &#x6A21;&#x5757;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x662F; CSS &#x6A21;&#x5757;&#xFF0C;&#x6216;&#x662F; Template &#x7B49;&#x6A21;&#x5757;&#x3002;&#x800C; Sea.js &#x5219;&#x4E13;&#x6CE8;&#x4E8E; JS &#x6587;&#x4EF6;&#x6A21;&#x5757;&#xFF1A;</p>
<ol>
<li>&#x6A21;&#x5757;&#x662F;&#x4E00;&#x6BB5; JavaScript &#x4EE3;&#x7801;&#xFF0C;&#x5177;&#x6709;&#x7EDF;&#x4E00;&#x7684; <strong>&#x57FA;&#x672C;&#x4E66;&#x5199;&#x683C;&#x5F0F;</strong></li>
<li>&#x6A21;&#x5757;&#x4E4B;&#x95F4;&#x901A;&#x8FC7;&#x57FA;&#x672C; <strong>&#x4EA4;&#x4E92;&#x89C4;&#x5219;</strong> &#xFF0C;&#x80FD;&#x5F7C;&#x6B64;&#x5F15;&#x7528;&#xFF0C;&#x534F;&#x540C;&#x5DE5;&#x4F5C;</li>
</ol>
<p>&#x628A;&#x4E0A;&#x9762;&#x4E24;&#x70B9;&#x4E2D;&#x63D0;&#x53CA;&#x7684;&#x57FA;&#x672C;&#x4E66;&#x5199;&#x683C;&#x5F0F;&#x548C;&#x57FA;&#x672C;&#x4EA4;&#x4E92;&#x89C4;&#x5219;&#x63CF;&#x8FF0;&#x6E05;&#x695A;&#xFF0C;&#x5C31;&#x80FD;&#x6784;&#x5EFA;&#x51FA;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x7CFB;&#x7EDF;&#x3002;&#x5BF9;&#x4E66;&#x5199;&#x683C;&#x5F0F;&#x548C;&#x4EA4;&#x4E92;&#x89C4;&#x5219;&#x7684;&#x8BE6;&#x7EC6;&#x63CF;&#x8FF0;&#xFF0C;&#x5C31;&#x662F;&#x6A21;&#x5757;&#x5B9A;&#x4E49;&#x89C4;&#x8303;&#xFF08;Module Definition Specification&#xFF09;&#x3002;</p>
<p>&#x6BD4;&#x5982; CommonJS &#x793E;&#x533A;&#x7684; <code>Modules 1.1.1</code> &#x89C4;&#x8303;&#xFF0C;&#x4EE5;&#x53CA; <code>NodeJS &#x7684; Modules</code> &#x89C4;&#x8303;&#xFF0C;&#x8FD8;&#x6709; RequireJS &#x63D0;&#x51FA;&#x7684; <code>AMD</code> &#x89C4;&#x8303;&#x7B49;&#x7B49;&#x3002;</p>
<p>Sea.js &#x9075;&#x5FAA;&#x7684;&#x662F; <code>CMD</code> &#x89C4;&#x8303;&#x3002;</p>
<h3 id="&#x5E38;&#x89C1;&#x7684;-JavaScript-&#x6A21;&#x5757;&#x5316;&#x89C4;&#x8303;"><a href="#&#x5E38;&#x89C1;&#x7684;-JavaScript-&#x6A21;&#x5757;&#x5316;&#x89C4;&#x8303;" class="headerlink" title="&#x5E38;&#x89C1;&#x7684; JavaScript &#x6A21;&#x5757;&#x5316;&#x89C4;&#x8303;"></a>&#x5E38;&#x89C1;&#x7684; JavaScript &#x6A21;&#x5757;&#x5316;&#x89C4;&#x8303;</h3><p>&#x89C4;&#x8303;&#x5176;&#x5B9E;&#x5C31;&#x662F;&#x8FD9;&#x4E9B;&#x5E93;&#x5728;&#x63A8;&#x5E7F;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#x9010;&#x6E10;&#x5F62;&#x6210;&#x7684;&#x4E00;&#x5957;&#x89C4;&#x5219;&#x3002;</p>
<p>&#x6240;&#x8C13;&#x7684;&#x89C4;&#x8303;&#x4E5F;&#x5C31;&#x662F;&#xFF1A;</p>
<ul>
<li>&#x5B9A;&#x4E49;&#x4E86;&#x6A21;&#x5757;&#x7684;&#x4E66;&#x5199;&#x683C;&#x5F0F;</li>
<li><p>&#x4EE5;&#x53CA;&#x6A21;&#x5757;&#x4E4B;&#x95F4;&#x7684;&#x4EA4;&#x4E92;&#x89C4;&#x5219;</p>
</li>
<li><p>Node &#x73AF;&#x5883;</p>
<ul>
<li>CommonJS</li>
<li>&#x8FD9;&#x91CC;&#x5148;&#x653E;&#x5728;&#x8FD9;&#x91CC;&#xFF0C;Node &#x8FD8;&#x6CA1;&#x6709;&#x5B66;&#x4E60;&#xFF0C;&#x5B66;&#x5230; Node &#x7684;&#x65F6;&#x5019;&#xFF0C;&#x518D;&#x8BF4;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;</li>
</ul>
</li>
<li>&#x6D4F;&#x89C8;&#x5668;&#x73AF;&#x5883;<ul>
<li>AMD<ul>
<li>RequireJS</li>
</ul>
</li>
<li>CMD Common Module Definition<ul>
<li>CMD &#x5C31;&#x662F; SeaJS &#x8FD9;&#x4E2A;&#x6A21;&#x5757;&#x52A0;&#x8F7D;&#x5668;&#x5728;&#x63A8;&#x5E7F;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#x5B9A;&#x4E49;&#x7684;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x89C4;&#x8303;</li>
</ul>
</li>
</ul>
</li>
<li>ECMAScript<ul>
<li>ECMAScript 6</li>
</ul>
</li>
<li>UMD</li>
</ul>
<p>CMD&#x3001;AMD&#x3001;CommonJS &#x90FD;&#x662F;&#x793E;&#x533A;&#x5236;&#x5B9A;&#x51FA;&#x6765;&#x7684;&#x6A21;&#x5757;&#x89C4;&#x8303;&#xFF0C;&#x4ED6;&#x4EEC;&#x7684;&#x76EE;&#x7684;&#x90FD;&#x662F;&#x4E3A;&#x4E86;&#x89E3;&#x51B3; JavaScript &#x6CA1;&#x6709;&#x6A21;&#x5757;&#x5316;&#x7CFB;&#x7EDF;&#x7684;&#x95EE;&#x9898;&#x3002;&#x4ED6;&#x4EEC;&#x90FD;&#x6709;&#x5982;&#x4F55;&#x5B9A;&#x4E49;&#x6A21;&#x5757;&#x6210;&#x5458;&#xFF0C;&#x4EE5;&#x53CA;&#x6A21;&#x5757;&#x6210;&#x5458;&#x4E4B;&#x95F4;&#x5982;&#x4F55;&#x8FDB;&#x884C;&#x901A;&#x4FE1;&#x4EA4;&#x4E92;&#x7684;&#x89C4;&#x5219;&#x3002;</p>
<p>2015 &#x5E74; 9 &#x6708;&#x4EFD;&#xFF0C;ECMAScript &#x5B98;&#x65B9;&#x63A8;&#x51FA;&#x4E86; ECMAScript 6 &#x8BED;&#x8A00;&#x6807;&#x51C6;&#x3002;&#x5728;&#x6700;&#x65B0;&#x7684; ES6 &#x8BED;&#x8A00;&#x89C4;&#x8303;&#x6807;&#x51C6;&#x4E2D;&#x5236;&#x5B9A;&#x4E86; JavaScript &#x6A21;&#x5757;&#x5316;&#x89C4;&#x8303;&#xFF0C;&#x901A;&#x8FC7; <code>export</code> &#x548C; <code>import</code> &#x4E24;&#x4E2A;&#x5173;&#x952E;&#x5B57;&#x6765;&#x4F5C;&#x4E3A;&#x4EA4;&#x4E92;&#x89C4;&#x5219;&#x3002;</p>
<p>ES6 &#x624D;&#x662F;&#x672A;&#x6765;&#x7684;&#x8D8B;&#x52BF;&#xFF0C;&#x4EE5;&#x540E;&#x7684;&#x5927;&#x4E00;&#x7EDF;&#x3002;</p>
<p>&#x524D;&#x7AEF;&#x53D1;&#x5C55;&#x975E;&#x5E38;&#x5FEB;&#xFF0C;&#x4E0D;&#x662F;&#x8BF4;&#x51FA;&#x4E86;&#x65B0;&#x6280;&#x672F;&#x9A6C;&#x4E0A;&#x5C31;&#x7528;&#xFF0C;&#x800C;&#x662F;&#x8FD9;&#x4E2A;&#x7834;&#x73A9;&#x513F;&#x8FD8;&#x6CA1;&#x53D1;&#x5E03;&#x6B63;&#x5F0F;&#x7248;&#xFF0C;&#x90FD;&#x5DF2;&#x7ECF;&#x603C;&#x5230;&#x751F;&#x4EA7;&#x73AF;&#x5883;&#x4E86;&#x3002;&#x6240;&#x6709;&#x4EFB;&#x4F55;&#x529F;&#x80FD;&#xFF0C;&#x90FD;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; js &#x6765;&#x5B9E;&#x73B0;&#x3002;</p>
<ul>
<li>electron<ul>
<li>&#x4F7F;&#x7528; HTML+CSS+JavaScript+Node &#x6784;&#x5EFA;&#x8DE8;&#x5E73;&#x53F0;&#x684C;&#x9762;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;</li>
</ul>
</li>
</ul>
<hr>
<h2 id="SeaJS"><a href="#SeaJS" class="headerlink" title="SeaJS"></a>SeaJS</h2><blockquote>
<p>A Module Loader for the Web, Enjoy the fun of programming.</p>
</blockquote>
<ul>
<li>&#x63D0;&#x4F9B;&#x7B80;&#x5355;&#x3001;&#x6781;&#x81F4;&#x7684;&#x6A21;&#x5757;&#x5316;&#x5F00;&#x53D1;&#x4F53;&#x9A8C;</li>
<li>A Module Loader for the Web</li>
<li>JavaScript &#x6A21;&#x5757;&#x52A0;&#x8F7D;&#x5668;</li>
<li>&#x53EF;&#x4EE5;&#x5B9E;&#x73B0; &#x5728; JavaScript &#x4EE3;&#x7801;&#x4E2D;&#x53BB;&#x52A0;&#x8F7D;&#x53E6;&#x4E00;&#x4E2A; JavaScript &#x4EE3;&#x7801;&#x3002;</li>
</ul>
<h3 id="SeaJS-&#x4ECB;&#x7ECD;"><a href="#SeaJS-&#x4ECB;&#x7ECD;" class="headerlink" title="SeaJS &#x4ECB;&#x7ECD;"></a>SeaJS &#x4ECB;&#x7ECD;</h3><p>SeaJS &#x5E26;&#x6765;&#x7684;&#x6700;&#x5927;&#x597D;&#x5904;&#x662F;&#xFF1A;&#x63D0;&#x5347;&#x4EE3;&#x7801;&#x7684;&#x53EF;&#x7EF4;&#x62A4;&#x6027;&#x3002;&#x5982;&#x679C;&#x4E00;&#x4E2A;&#x7F51;&#x7AD9;&#x7684; JS &#x6587;&#x4EF6;&#x8D85;&#x8FC7; 3 &#x4E2A;&#xFF0C;&#x5C31;&#x9002;&#x5408;&#x7528; SeaJS &#x6765;&#x7EC4;&#x7EC7;&#x548C;&#x7EF4;&#x62A4;&#x4EE3;&#x7801;&#x3002;&#x6D89;&#x53CA;&#x7684; JS &#x6587;&#x4EF6;&#x8D8A;&#x591A;&#xFF0C;SeaJS &#x5C31;&#x8D8A;&#x9002;&#x5408;&#x3002;</p>
<ul>
<li><p>&#x5173;&#x4E8E; SeaJS</p>
<ul>
<li>SeaJS &#x662F;&#x4E00;&#x4E2A;&#x9002;&#x7528;&#x4E8E;&#x6D4F;&#x89C8;&#x5668;&#x73AF;&#x5883;&#x7684; JavaScript &#x6A21;&#x5757;&#x52A0;&#x8F7D;&#x5668;<ul>
<li>&#x4E00;&#x4E2A;&#x5E93;&#x6587;&#x4EF6;&#xFF0C;&#x7C7B;&#x4F3C;&#x4E8E; jQuery</li>
<li>&#x4F7F;&#x7528;&#x8FD9;&#x4E2A;&#x5E93;&#x63D0;&#x4F9B;&#x7684;&#x89C4;&#x8303;&#x7684;&#x6A21;&#x5757;&#x5316;&#x7684;&#x65B9;&#x5F0F;&#x6765;&#x7F16;&#x5199; JavaScript &#x4EE3;&#x7801;</li>
<li>&#x53EA;&#x5173;&#x5FC3; JavaScript &#x6587;&#x4EF6;&#x4EE3;&#x7801;&#x6A21;&#x5757;&#x5982;&#x4F55;&#x7EC4;&#x7EC7;</li>
<li>&#x53EA;&#x5173;&#x5FC3; JavaScript &#x6587;&#x4EF6;&#x4E4B;&#x95F4;&#x5982;&#x4F55;&#x76F8;&#x4E92;&#x534F;&#x8BAE;&#x3001;&#x5F15;&#x7528;&#x3001;&#x4F9D;&#x8D56;</li>
</ul>
</li>
<li>SeaJS &#x7684;&#x4F5C;&#x8005;&#x662F;&#x963F;&#x91CC;&#x5DF4;&#x5DF4;&#x652F;&#x4ED8;&#x5B9D;&#x524D;&#x7AEF;&#x67B6;&#x6784;&#x5E08;&#xFF1A;&#x7389;&#x4F2F;<ul>
<li><a href="http://www.csdn.net/article/2013-09-03/2816801-front-end-development-seajs-framework" target="_blank" rel="external">Sea.js&#x521B;&#x59CB;&#x4EBA;&#x7389;&#x4F2F;&#x7684;&#x524D;&#x7AEF;&#x5F00;&#x53D1;&#x4E4B;&#x8DEF;</a></li>
</ul>
</li>
<li><a href="http://seajs.org/" target="_blank" rel="external">SeaJS</a></li>
<li><a href="https://github.com/seajs/seajs/" target="_blank" rel="external">SeaJS -github</a></li>
</ul>
</li>
<li><p>&#x4E3A;&#x4EC0;&#x4E48;&#x5B66;&#x4E60;&#x548C;&#x4F7F;&#x7528; SeaJS &#xFF1F;</p>
<ul>
<li><strong>&#x7B80;&#x5355;&#x53CB;&#x597D;&#x7684;&#x6A21;&#x5757;&#x5B9A;&#x4E49;&#x89C4;&#x8303;</strong>&#xFF1A;SeaJS &#x9075;&#x5FAA; CMD &#x89C4;&#x8303;&#xFF0C;&#x53EF;&#x4EE5;&#x50CF; Node &#x4E00;&#x6837;&#x4E66;&#x5199;&#x6A21;&#x5757;&#x4EE3;&#x7801;</li>
<li><strong>&#x81EA;&#x7136;&#x76F4;&#x89C2;&#x7684;&#x4EE3;&#x7801;&#x7EC4;&#x7EC7;&#x65B9;&#x5F0F;</strong>&#xFF1A;&#x4F9D;&#x8D56;&#x7684;&#x81EA;&#x52A8;&#x52A0;&#x8F7D;&#x3001;&#x914D;&#x7F6E;&#x7B80;&#x6D01;&#x6E05;&#x6670;&#xFF0C;&#x53EF;&#x4EE5;&#x8BA9;&#x6211;&#x4EEC;&#x66F4;&#x591A;&#x7684;&#x4EAB;&#x53D7;&#x7F16;&#x7801;&#x7684;&#x4E50;&#x8DA3;</li>
<li>SeaJS&#x517C;&#x5BB9;&#x6027;&#x975E;&#x5E38;&#x597D;&#xFF0C;&#x51E0;&#x4E4E;&#x53EF;&#x4EE5;&#x8FD0;&#x884C;&#x5728;&#x4EFB;&#x4F55;&#x6D4F;&#x89C8;&#x5668;&#x5F15;&#x64CE;&#x4E0A;</li>
<li>&#x6CE8;1&#xFF1A;SeaJS &#x53EA;&#x662F;&#x5B9E;&#x73B0;&#x6A21;&#x5757;&#x5316;&#x5F00;&#x53D1;&#x7684;&#x4E00;&#x79CD;&#x65B9;&#x5F0F;&#x6216;&#x8005;&#x8BF4;&#x4E00;&#x79CD;&#x5DE5;&#x5177;&#x800C;&#x5DF2;&#xFF0C;&#x91CD;&#x5728;&#x6A21;&#x5757;&#x5316;&#x601D;&#x60F3;&#x7684;&#x7406;&#x89E3;</li>
<li>&#x6CE8;2&#xFF1A;&#x56E0;&#x4E3A; SeaJS &#x91C7;&#x7528;&#x7684; CMD &#x6A21;&#x5757;&#x89C4;&#x8303;&#x548C; Node &#x4E2D;&#x7684; CommonJS &#x6A21;&#x5757;&#x89C4;&#x8303;&#x975E;&#x5E38;&#x4E00;&#x81F4;&#xFF0C;&#x6240;&#x4EE5;&#x6709;&#x5229;&#x4E8E;&#x6211;&#x4EEC;&#x5B66;&#x4E60; Node &#x4E2D;&#x7684;&#x6A21;&#x5757;&#x5316;&#x7F16;&#x7A0B;</li>
</ul>
</li>
<li><p>&#x8C01;&#x5728;&#x7528;&#xFF1F;</p>
<ul>
<li>&#x6DD8;&#x5B9D;&#x7F51;&#x3001;&#x652F;&#x4ED8;&#x5B9D;&#x3001;&#x4EAC;&#x4E1C;&#x3001;&#x7231;&#x5947;&#x827A;&#x3002;&#x3002;&#x3002;</li>
</ul>
</li>
<li><p>SeaJS &#x4F7F;&#x7528;&#x573A;&#x666F;</p>
<ul>
<li>SeaJS &#x4E0D;&#x63D0;&#x4F9B;&#x4EFB;&#x4F55;&#x529F;&#x80FD;&#x6027; API&#xFF0C;&#x53EA;&#x63D0;&#x4F9B;&#x4E86;&#x89E3;&#x51B3; JavaScript &#x4EE3;&#x7801;&#x7684;&#x547D;&#x540D;&#x6C61;&#x67D3;&#x548C;&#x6587;&#x4EF6;&#x4F9D;&#x8D56;&#x7684;&#x95EE;&#x9898;</li>
<li>&#x6240;&#x4EE5; SeaJS &#x53EF;&#x4EE5;&#x548C; jQuery&#x3001;underscore &#x7B49;&#x5E93;&#x7ED3;&#x5408;&#x4F7F;&#x7528;</li>
<li>&#x4F8B;&#x5982; &#x53EA;&#x5199;&#x5199; &#x539F;&#x751F; JavaScript &#x6216;&#x8005;&#x7528;&#x4E86;&#x4E00;&#x4E9B;&#x7B2C;&#x4E09;&#x65B9;&#x5E93;</li>
</ul>
</li>
</ul>
<h3 id="&#x5FEB;&#x901F;&#x4E0A;&#x624B;&#xFF08;Getting-Started&#xFF09;"><a href="#&#x5FEB;&#x901F;&#x4E0A;&#x624B;&#xFF08;Getting-Started&#xFF09;" class="headerlink" title="&#x5FEB;&#x901F;&#x4E0A;&#x624B;&#xFF08;Getting Started&#xFF09;"></a>&#x5FEB;&#x901F;&#x4E0A;&#x624B;&#xFF08;Getting Started&#xFF09;</h3><ol>
<li>&#x4E0B;&#x8F7D; sea.js &#x5E93;&#x6587;&#x4EF6;<ul>
<li><a href="https://github.com/seajs/seajs/releases" target="_blank" rel="external">SeaJS - Release</a></li>
<li><code>bower install seajs</code></li>
<li><code>npm install seajs</code></li>
</ul>
</li>
<li>&#x5728;&#x9875;&#x9762;&#x4E2D;&#x5F15;&#x5165; sea.js</li>
<li>&#x4F7F;&#x7528; <code>define</code> &#x51FD;&#x6570;&#x5B9A;&#x4E49;&#x6A21;&#x5757;</li>
<li>&#x4F7F;&#x7528; <code>require</code> &#x51FD;&#x6570;&#x52A0;&#x8F7D;&#x6A21;&#x5757;</li>
<li>&#x4F7F;&#x7528; <code>module.exports</code> &#x5BF9;&#x5916;&#x66B4;&#x9732;&#x63A5;&#x53E3;&#x5BF9;&#x8C61;</li>
<li>&#x4F7F;&#x7528; <code>seajs.use</code> &#x51FD;&#x6570;&#x542F;&#x52A8;&#x6A21;&#x5757;&#x7CFB;&#x7EDF;</li>
</ol>
<h3 id="API-&#x8BE6;&#x89E3;"><a href="#API-&#x8BE6;&#x89E3;" class="headerlink" title="API &#x8BE6;&#x89E3;"></a>API &#x8BE6;&#x89E3;</h3><h4 id="seajs-use-&#x52A0;&#x8F7D;&#x6A21;&#x5757;-&#x666E;&#x901A;&#x8DEF;&#x5F84;"><a href="#seajs-use-&#x52A0;&#x8F7D;&#x6A21;&#x5757;-&#x666E;&#x901A;&#x8DEF;&#x5F84;" class="headerlink" title="seajs.use &#x52A0;&#x8F7D;&#x6A21;&#x5757;-&#x666E;&#x901A;&#x8DEF;&#x5F84;"></a><code>seajs.use</code> &#x52A0;&#x8F7D;&#x6A21;&#x5757;-&#x666E;&#x901A;&#x8DEF;&#x5F84;</h4><p>&#x52A0;&#x8F7D;&#x6A21;&#x5757;&#xFF0C;&#x542F;&#x52A8;&#x6A21;&#x5757;&#x7CFB;&#x7EDF;&#x3002;</p>
<ul>
<li>&#x52A0;&#x8F7D;&#x4E00;&#x4E2A;&#x6A21;&#x5757; <code>seajs.use(&apos;id&apos;)</code></li>
<li>&#x52A0;&#x8F7D;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#xFF0C;&#x5728;&#x52A0;&#x8F7D;&#x5B8C;&#x6210;&#x65F6;&#xFF0C;&#x6267;&#x884C;&#x56DE;&#x8C03; <code>seajs.use(&apos;id&apos;, callback)</code></li>
<li><p>&#x52A0;&#x8F7D;&#x591A;&#x4E2A;&#x6A21;&#x5757;&#xFF0C;&#x52A0;&#x8F7D;&#x5B8C;&#x6210;&#x65F6;&#xFF0C;&#x6267;&#x884C;&#x56DE;&#x8C03; <code>seajs.use([&apos;id1&apos;,&apos;id2&apos;,...],callback)</code></p>
</li>
<li><p>&#x6CE8;&#x610F;&#xFF1A;</p>
<ul>
<li>&#x5728;&#x8C03;&#x7528; seajs.use &#x4E4B;&#x524D;&#xFF0C;&#x9700;&#x8981;&#x5148;&#x5F15;&#x5165; sea.js &#x6587;&#x4EF6;</li>
<li>seajs.use &#x4E0E; <code>DOM ready</code> &#x4E8B;&#x4EF6;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x5173;&#x7CFB;&#x3002;&#x5982;&#x679C;&#x67D0;&#x4E9B;&#x64CD;&#x4F5C;&#x8981;&#x786E;&#x4FDD;&#x5728; <code>DOM ready</code> &#x540E;&#x6267;&#x884C;&#xFF0C;&#x9700;&#x8981;&#x4F7F;&#x7528; jquery &#x7B49;&#x7C7B;&#x5E93;&#x6765;&#x4FDD;&#x8BC1;</li>
<li>seajs.use &#x7406;&#x8BBA;&#x4E0A;&#x53EA;&#x7528;&#x4E8E;&#x52A0;&#x8F7D;&#x542F;&#x52A8;&#xFF0C;&#x4E0D;&#x5E94;&#x8BE5;&#x51FA;&#x73B0;&#x5728; <code>define</code> &#x4E2D;&#x7684;&#x6A21;&#x5757;&#x4EE3;&#x7801;&#x91CC;</li>
</ul>
</li>
</ul>
<h4 id="define-factory"><a href="#define-factory" class="headerlink" title="define(factory)"></a><code>define(factory)</code></h4><ul>
<li><code>define</code> &#x662F;&#x4E00;&#x4E2A;&#x5168;&#x5C40;&#x51FD;&#x6570;&#xFF0C;&#x7528;&#x6765;&#x5B9A;&#x4E49;&#x6A21;&#x5757;&#x3002;</li>
<li><code>define</code> &#x63A5;&#x53D7; <code>factory</code> &#x53C2;&#x6570;&#xFF0C;<code>factory</code> &#x53EF;&#x4EE5;&#x662F;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x662F;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x6216;&#x5B57;&#x7B26;&#x4E32;&#x3002;</li>
<li><code>factory</code> &#x4E3A;&#x5BF9;&#x8C61;&#x3001;&#x5B57;&#x7B26;&#x4E32;&#x65F6;&#xFF0C;&#x8868;&#x793A;&#x6A21;&#x5757;&#x7684;&#x63A5;&#x53E3;&#x5C31;&#x662F;&#x8BE5;&#x5BF9;&#x8C61;&#x3001;&#x5B57;&#x7B26;&#x4E32;&#x3002;</li>
<li>factory &#x662F;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;<ul>
<li><code>define({})</code></li>
</ul>
</li>
<li>factory &#x662F;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x65F6;<ul>
<li><code>define(&apos;hello&apos;)</code></li>
</ul>
</li>
<li>factory &#x662F;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x65F6;<ul>
<li><code>define(function(require, exports, module){})</code></li>
</ul>
</li>
</ul>
<h4 id="require-&#x89E3;&#x51B3;&#x4F9D;&#x8D56;"><a href="#require-&#x89E3;&#x51B3;&#x4F9D;&#x8D56;" class="headerlink" title="require &#x89E3;&#x51B3;&#x4F9D;&#x8D56;"></a><code>require</code> &#x89E3;&#x51B3;&#x4F9D;&#x8D56;</h4><blockquote>
<p>&#x76F8;&#x5BF9;&#x8DEF;&#x5F84;&#xFF1A;&#x76F8;&#x5BF9;&#x4E8E;&#x5F53;&#x524D;&#x6A21;&#x5757;&#x6765;&#x8BF4;&#x7684;</p>
</blockquote>
<ul>
<li>require &#x7528;&#x6765;&#x52A0;&#x8F7D;&#x4E00;&#x4E2A; js &#x6587;&#x4EF6;&#x6A21;&#x5757;&#xFF0C;&#x76F8;&#x5BF9;&#x8DEF;&#x5F84;&#xFF1A;&#x76F8;&#x5BF9;&#x4E8E;&#x5F53;&#x524D;&#x6A21;&#x5757;&#x6765;&#x8BF4;&#x7684;</li>
<li>require &#x7528;&#x6765;&#x83B7;&#x53D6;&#x6307;&#x5B9A;&#x6A21;&#x5757;&#x7684;&#x63A5;&#x53E3;&#x5BF9;&#x8C61; <code>module.exports</code>&#x3002;</li>
<li>require &#x5728;&#x52A0;&#x8F7D;&#x548C;&#x6267;&#x884C;&#x7684;&#x65F6;&#x5019;&#xFF0C;js &#x4F1A;&#x6309;&#x7167;&#x540C;&#x6B65;&#x7684;&#x65B9;&#x5F0F;&#x548C;&#x6267;&#x884C;&#x3002;</li>
</ul>
<p>&#x4F7F;&#x7528;&#x6CE8;&#x610F;&#xFF1A;</p>
<ul>
<li>&#x6B63;&#x786E;&#x62FC;&#x5199;<ul>
<li>&#x6A21;&#x5757; factory &#x6784;&#x9020;&#x65B9;&#x6CD5;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570; <code>&#x5FC5;&#x987B;</code> &#x547D;&#x540D;&#x4E3A; require</li>
</ul>
</li>
<li>&#x4E0D;&#x8981;&#x4FEE;&#x6539;<ul>
<li>&#x4E0D;&#x8981;&#x91CD;&#x547D;&#x540D; require &#x51FD;&#x6570;&#xFF0C;&#x6216;&#x5728;&#x4EFB;&#x4F55;&#x4F5C;&#x7528;&#x57DF;&#x4E2D;&#x7ED9; require &#x91CD;&#x65B0;&#x8D4B;&#x503C;</li>
</ul>
</li>
<li>&#x4F7F;&#x7528;&#x5B57;&#x7B26;&#x4E32;&#x76F4;&#x63A5;&#x91CF;<ul>
<li>require &#x7684;&#x53C2;&#x6570;&#x503C; &#x5FC5;&#x987B; &#x662F;&#x5B57;&#x7B26;&#x4E32;&#x76F4;&#x63A5;&#x91CF;</li>
</ul>
</li>
</ul>
<h4 id="&#x6A21;&#x5757;&#x6807;&#x8BC6;"><a href="#&#x6A21;&#x5757;&#x6807;&#x8BC6;" class="headerlink" title="&#x6A21;&#x5757;&#x6807;&#x8BC6;"></a>&#x6A21;&#x5757;&#x6807;&#x8BC6;</h4><p>&#x6A21;&#x5757;&#x6807;&#x8BC6;&#x662F;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x7528;&#x6765;&#x6807;&#x8BC6;&#x6A21;&#x5757;&#x3002;</p>
<ul>
<li>&#x6A21;&#x5757;&#x6807;&#x8BC6;&#x53EF;&#x4EE5;&#x4E0D;&#x5305;&#x542B;&#x6587;&#x4EF6;&#x540E;&#x7F00;&#x540D;&#xFF0C;&#x6BD4;&#x5982; <code>.js</code><ul>
<li>seajs &#x63A8;&#x8350;&#x4E0D;&#x52A0; .js &#x6587;&#x4EF6;&#x6A21;&#x5757;&#x540E;&#x7F00;</li>
</ul>
</li>
<li>&#x6A21;&#x5757;&#x6807;&#x8BC6;&#x53EF;&#x4EE5;&#x662F; <strong>&#x76F8;&#x5BF9;</strong> &#x6216; <strong>&#x9876;&#x7EA7;</strong> &#x6807;&#x8BC6;</li>
<li>&#x76F8;&#x5BF9;&#x6807;&#x8BC6;</li>
</ul>
<p>&#x76F8;&#x5BF9;&#x6807;&#x8BC6;&#x4EE5; <code>.</code> &#x5F00;&#x5934;&#xFF0C;&#x6C38;&#x8FDC;&#x76F8;&#x5BF9;&#x4E8E;&#x5F53;&#x524D;&#x6A21;&#x5757;&#x6240;&#x5904;&#x7684;&#x8DEF;&#x5F84;&#x6765;&#x89E3;&#x6790;&#x3002;</p>
<ul>
<li>&#x9876;&#x7EA7;&#x6807;&#x8BC6;</li>
</ul>
<p>&#x9876;&#x7EA7;&#x6807;&#x8BC6;&#x4E0D;&#x4EE5; <code>.</code> &#x6216; <code>/</code> &#x5F00;&#x59CB;&#xFF0C;&#x4F1A;&#x76F8;&#x5BF9;&#x6A21;&#x5757;&#x7CFB;&#x7EDF;&#x7684;&#x57FA;&#x7840;&#x8DEF;&#x5F84;&#xFF08;base&#x8DEF;&#x5F84;&#xFF0C;&#x9ED8;&#x8BA4;&#x662F; sea.js &#x6587;&#x4EF6;&#x6240;&#x5C5E;&#x7684;&#x8DEF;&#x5F84;&#xFF09;&#x3002;&#x53EF;&#x4EE5;&#x624B;&#x52A8;&#x914D;&#x7F6E; base &#x8DEF;&#x5F84;&#x3002;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">seajs.config({</div><div class="line">  <span class="attr">base</span>: <span class="string">&apos;./js&apos;</span>;</div><div class="line">})</div></pre></td></tr></table></figure>
<ul>
<li>&#x666E;&#x901A;&#x8DEF;&#x5F84;&#xFF08;&#x76F8;&#x5BF9;&#x4E8E; html &#x8DEF;&#x5F84;&#x6765;&#x8BF4;&#x7684;&#xFF09;</li>
</ul>
<p>&#x9664;&#x4E86;&#x76F8;&#x5BF9;&#x548C;&#x9876;&#x7EA7;&#x6807;&#x8BC6;&#x4E4B;&#x5916;&#x7684;&#x6807;&#x8BC6;&#x90FD;&#x662F;&#x666E;&#x901A;&#x8DEF;&#x5F84;&#x3002;&#x666E;&#x901A;&#x8DEF;&#x5F84;&#x7684;&#x89E3;&#x6790;&#x89C4;&#x5219;&#xFF0C;&#x4F1A;&#x76F8;&#x5BF9;&#x5F53;&#x524D;&#x9875;&#x9762;&#x89E3;&#x6790;&#x3002;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"><span class="comment">// &#x5047;&#x8BBE;&#x5F53;&#x524D;&#x9875;&#x9762;&#x662F; http://example.com/path/to/page/index.html</span></div><div class="line"><span class="comment">// &#x7EDD;&#x5BF9;&#x8DEF;&#x5F84;&#x662F;&#x666E;&#x901A;&#x8DEF;&#x5F84;&#xFF1A;</span></div><div class="line"><span class="built_in">require</span>.resolve(<span class="string">&apos;http://cdn.com/js/a&apos;</span>);</div><div class="line"><span class="comment">// =&gt; http://cdn.com/js/a.js</span></div><div class="line"><span class="comment">// &#x6839;&#x8DEF;&#x5F84;&#x662F;&#x666E;&#x901A;&#x8DEF;&#x5F84;&#xFF1A;</span></div><div class="line"><span class="built_in">require</span>.resolve(<span class="string">&apos;/js/b&apos;</span>);</div><div class="line"><span class="comment">// =&gt; http://example.com/js/b.js</span></div><div class="line"><span class="comment">// use &#x4E2D;&#x7684;&#x76F8;&#x5BF9;&#x8DEF;&#x5F84;&#x59CB;&#x7EC8;&#x662F;&#x666E;&#x901A;&#x8DEF;&#x5F84;&#xFF1A;</span></div><div class="line">seajs.use(<span class="string">&apos;./c&apos;</span>);</div><div class="line">  <span class="comment">// =&gt; &#x52A0;&#x8F7D;&#x7684;&#x662F; http://example.com/path/to/page/c.js</span></div><div class="line">seajs.use(<span class="string">&apos;../d&apos;</span>);</div><div class="line">  <span class="comment">// =&gt; &#x52A0;&#x8F7D;&#x7684;&#x662F; http://example.com/path/to/d.js</span></div></pre></td></tr></table></figure>
<p><strong>Tips</strong>:</p>
<ul>
<li>&#x9876;&#x7EA7;&#x6807;&#x8BC6;&#x59CB;&#x7EC8;&#x76F8;&#x5BF9; <code>base</code> &#x57FA;&#x7840;&#x8DEF;&#x5F84;&#x89E3;&#x6790;&#x3002;<ul>
<li>&#x5982;&#x679C;&#x4E0D;&#x8BBE;&#x7F6E;&#xFF0C;base &#x8DEF;&#x5F84;&#x9ED8;&#x8BA4;&#x5C31;&#x662F; sea.js &#x5E93;&#x6587;&#x4EF6;&#x6240;&#x5C5E;&#x7684;&#x8DEF;&#x5F84;</li>
<li>&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>seajs.config({ base: &apos;&#x57FA;&#x7840;&#x8DEF;&#x5F84;&apos; })</code> &#x6765;&#x914D;&#x7F6E;&#x57FA;&#x7840;&#x8DEF;&#x5F84;</li>
</ul>
</li>
<li>&#x7EDD;&#x5BF9;&#x8DEF;&#x5F84;&#x548C;&#x6839;&#x8DEF;&#x5F84;&#x59CB;&#x7EC8;&#x76F8;&#x5BF9;&#x5F53;&#x524D;&#x9875;&#x9762;&#x89E3;&#x6790;&#x3002;</li>
<li>&#x76F8;&#x5BF9;&#x6807;&#x8BC6;&#x6C38;&#x8FDC;&#x76F8;&#x5BF9;&#x4E8E;&#x5F53;&#x524D;&#x6587;&#x4EF6;</li>
<li><code>seajs.use</code> &#x4E2D;&#x7684;&#x76F8;&#x5BF9;&#x8DEF;&#x5F84;&#x59CB;&#x7EC8;&#x76F8;&#x5BF9;&#x5F53;&#x524D;&#x9875;&#x9762;&#x6765;&#x89E3;&#x6790;&#x3002;</li>
</ul>
<h4 id="module"><a href="#module" class="headerlink" title="module"></a>module</h4><p>module &#x662F;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x4E0A;&#x9762;&#x5B58;&#x50A8;&#x4E86;&#x4E0E;&#x5F53;&#x524D;&#x6A21;&#x5757;&#x76F8;&#x5173;&#x8054;&#x7684;&#x4E00;&#x4E9B;&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;&#x3002;</p>
<ul>
<li><code>module.id</code><ul>
<li>&#x6A21;&#x5757;&#x7684;&#x552F;&#x4E00;&#x6807;&#x8BC6;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>define</code> &#x65B9;&#x6CD5;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x6765;&#x6307;&#x5B9A;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;&#x8BE5;&#x6A21;&#x5757;&#x6587;&#x4EF6;&#x7684;&#x7EDD;&#x5BF9;&#x8DEF;&#x5F84;</li>
</ul>
</li>
<li><code>module.uri</code><ul>
<li>&#x6A21;&#x5757;&#x7684;&#x7EDD;&#x5BF9;&#x8DEF;&#x5F84;</li>
</ul>
</li>
<li><code>module.dependencies</code><ul>
<li>dependencies &#x662F;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#xFF0C;&#x8868;&#x793A;&#x5F53;&#x524D;&#x6A21;&#x5757;&#x7684;&#x4F9D;&#x8D56;</li>
</ul>
</li>
<li><code>module.exports</code><ul>
<li>&#x5F53;&#x524D;&#x6A21;&#x5757;&#x5BF9;&#x5916;&#x63D0;&#x4F9B;&#x7684;&#x63A5;&#x53E3;&#x5BF9;&#x8C61;</li>
<li>&#x76F8;&#x5F53;&#x4E8E;&#x6BCF;&#x4E2A;&#x6A21;&#x5757;&#x5185;&#x90E8;&#x6700;&#x7EC8;&#x90FD;&#x6267;&#x884C;&#x4E86;&#x8FD9;&#x4E48;&#x4E00;&#x53E5;&#x8BDD;&#xFF1A;<code>return module.exports</code></li>
<li>&#x6A21;&#x5757;&#x4E0E;&#x6A21;&#x5757;&#x4E4B;&#x95F4;&#x7684;&#x901A;&#x4FE1;&#x63A5;&#x53E3;</li>
</ul>
</li>
</ul>
<h4 id="exports"><a href="#exports" class="headerlink" title="exports"></a>exports</h4><p>exports &#x4EC5;&#x4EC5;&#x662F; module.exports &#x7684;&#x4E00;&#x4E2A;&#x5F15;&#x7528;&#x3002;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#x4FEE;&#x6539;&#x4E86; exports &#x5C31;&#x76F8;&#x5F53;&#x4E8E;&#x4FEE;&#x6539;&#x4E86; module.exports&#x3002;</p>
<p>&#x4F46;&#x662F;&#x4E00;&#x65E6;&#x5728; factory &#x5185;&#x90E8;&#x7ED9; exports &#x91CD;&#x65B0;&#x8D4B;&#x503C;&#xFF0C;&#x5E76;&#x4E0D;&#x4F1A;&#x6539;&#x53D8; module.exports &#x7684;&#x503C;&#x3002;&#x56E0;&#x6B64;&#x7ED9; exports &#x8D4B;&#x503C;&#x662F;&#x65E0;&#x6548;&#x7684;&#x3002;</p>
<blockquote>
<p>return &#x4E5F;&#x662F;&#x66B4;&#x9732;&#xFF0C;&#x7B49;&#x4E8E; module.exports</p>
</blockquote>
<p>&#x4F8B;&#x5982; jQuery &#x6A21;&#x5757;&#x5316;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line"><span class="comment">// support seajs</span></div><div class="line"><span class="keyword">if</span> ( <span class="keyword">typeof</span> define === <span class="string">&quot;function&quot;</span> &amp;&amp; define.cmd ) {</div><div class="line">  define( <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>{ <span class="keyword">return</span> jQuery; } );</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">// or</span></div><div class="line"><span class="keyword">if</span> ( <span class="keyword">typeof</span> define === <span class="string">&quot;function&quot;</span> &amp;&amp; define.cmd ) {</div><div class="line">  define( <span class="function"><span class="keyword">function</span> (<span class="params">require, exports, module</span>) </span>{ </div><div class="line">    <span class="built_in">module</span>.exports = jQuery;</div><div class="line">  });</div><div class="line">}</div></pre></td></tr></table></figure>
<p>jQuery &#x63D2;&#x4EF6;&#x5305;&#x88C5;&#x6210;&#x6A21;&#x5757;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">(<span class="function"><span class="keyword">function</span>(<span class="params">factory</span>)</span>{</div><div class="line">  <span class="keyword">if</span>(<span class="keyword">typeof</span> define === <span class="string">&apos;function&apos;</span> &amp;&amp; define.cmd) {</div><div class="line">    define(<span class="function"><span class="keyword">function</span>(<span class="params">require</span>)</span>{</div><div class="line">      <span class="keyword">var</span> $ = <span class="built_in">require</span>(<span class="string">&apos;jquery&apos;</span>);</div><div class="line">      factory($);</div><div class="line">    });</div><div class="line">  }</div><div class="line">})(<span class="function"><span class="keyword">function</span>(<span class="params">$</span>)</span>{</div><div class="line">  <span class="comment">// jQuery &#x7684;&#x63D2;&#x4EF6;&#x4EE3;&#x7801;</span></div><div class="line">})</div></pre></td></tr></table></figure>
<h3 id="exports-&#x548C;-module-exports-&#x7684;&#x533A;&#x522B;"><a href="#exports-&#x548C;-module-exports-&#x7684;&#x533A;&#x522B;" class="headerlink" title="exports &#x548C; module.exports &#x7684;&#x533A;&#x522B;"></a>exports &#x548C; module.exports &#x7684;&#x533A;&#x522B;</h3><ul>
<li>&#x6BCF;&#x4E2A;&#x6A21;&#x5757;&#x5185;&#x90E8;&#x5BF9;&#x5916;&#x5230;&#x5904;&#x7684;&#x63A5;&#x53E3;&#x5BF9;&#x8C61;&#x59CB;&#x7EC8;&#x90FD;&#x662F; <code>module.exports</code></li>
<li>&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4FEE;&#x6539; <code>module.exports</code> &#x6216;&#x7ED9;&#x5B83;&#x8D4B;&#x503C;&#x6539;&#x53D8;&#x6A21;&#x5757;&#x63A5;&#x53E3;&#x5BF9;&#x8C61;</li>
<li><code>exports</code> &#x662F; <code>module.exports</code> &#x7684;&#x4E00;&#x4E2A;&#x5F15;&#x7528;&#xFF0C;&#x5C31;&#x597D;&#x6BD4;&#x5728;&#x6BCF;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x5B9A;&#x4E49;&#x6700;&#x5F00;&#x59CB;&#x7684;&#x5730;&#x65B9;&#x5199;&#x4E86;&#x8FD9;&#x4E48;&#x4E00;&#x53E5;&#x4EE3;&#x7801;&#xFF1A;<code>var exports = module.exports</code></li>
</ul>
<p>&#x5206;&#x6790;&#x4E0B;&#x9762;&#x4EE3;&#x7801;&#xFF1A;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> <span class="built_in">module</span> = {</div><div class="line">  <span class="attr">exports</span>: {}</div><div class="line">}</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">changeExports</span> (<span class="params">exports, module</span>) </span>{</div><div class="line">  <span class="comment">// var exports = module.exports</span></div><div class="line">  exports.foo = <span class="string">&apos;bar&apos;</span></div><div class="line">  <span class="comment">// &#x8FD9;&#x91CC;&#x8D4B;&#x503C;&#x62FF;&#x4E0D;&#x5230;&#xFF0C;&#x4E0D;&#x8981;&#x4F7F;&#x7528;&#x4F7F;&#x7528;</span></div><div class="line">  <span class="comment">// exports = function () {}</span></div><div class="line">  <span class="keyword">return</span> <span class="built_in">module</span>.exports</div><div class="line">}</div><div class="line">changeExports(<span class="built_in">module</span>.exports, <span class="built_in">module</span>)</div></pre></td></tr></table></figure>
<h3 id="&#x5982;&#x4F55;&#x5C06;&#x4E00;&#x4E2A;&#x666E;&#x901A;&#x7684;&#x6A21;&#x5757;&#x6587;&#x4EF6;&#x6539;&#x9020;&#x4E3A;&#x517C;&#x5BB9;-CMD-&#x89C4;&#x8303;&#x7684;&#x6A21;&#x5757;"><a href="#&#x5982;&#x4F55;&#x5C06;&#x4E00;&#x4E2A;&#x666E;&#x901A;&#x7684;&#x6A21;&#x5757;&#x6587;&#x4EF6;&#x6539;&#x9020;&#x4E3A;&#x517C;&#x5BB9;-CMD-&#x89C4;&#x8303;&#x7684;&#x6A21;&#x5757;" class="headerlink" title="&#x5982;&#x4F55;&#x5C06;&#x4E00;&#x4E2A;&#x666E;&#x901A;&#x7684;&#x6A21;&#x5757;&#x6587;&#x4EF6;&#x6539;&#x9020;&#x4E3A;&#x517C;&#x5BB9; CMD &#x89C4;&#x8303;&#x7684;&#x6A21;&#x5757;"></a>&#x5982;&#x4F55;&#x5C06;&#x4E00;&#x4E2A;&#x666E;&#x901A;&#x7684;&#x6A21;&#x5757;&#x6587;&#x4EF6;&#x6539;&#x9020;&#x4E3A;&#x517C;&#x5BB9; CMD &#x89C4;&#x8303;&#x7684;&#x6A21;&#x5757;</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">if</span> (<span class="keyword">typeof</span> define === <span class="string">&quot;function&quot;</span> &amp;&amp; define.cmd) {</div><div class="line">  <span class="comment">// &#x6709; Sea.js &#x7B49; CMD &#x6A21;&#x5757;&#x52A0;&#x8F7D;&#x5668;&#x5B58;&#x5728;</span></div><div class="line">  define(<span class="function"><span class="keyword">function</span> (<span class="params">require, exports, module</span>) </span>{</div><div class="line">    <span class="comment">// &#x4F7F;&#x7528; module.exports &#x5411;&#x5916;&#x66B4;&#x9732;&#x63A5;&#x53E3;&#x5BF9;&#x8C61;</span></div><div class="line">  })</div><div class="line">}</div></pre></td></tr></table></figure>
<h3 id="&#x9AD8;&#x7EA7;&#x914D;&#x7F6E;-seajs-config-options"><a href="#&#x9AD8;&#x7EA7;&#x914D;&#x7F6E;-seajs-config-options" class="headerlink" title="&#x9AD8;&#x7EA7;&#x914D;&#x7F6E; seajs.config(options)"></a>&#x9AD8;&#x7EA7;&#x914D;&#x7F6E; <code>seajs.config(options)</code></h3><p>&#x53EF;&#x4EE5;&#x5BF9; Sea.js &#x8FDB;&#x884C;&#x914D;&#x7F6E;&#xFF0C;&#x8BA9;&#x6A21;&#x5757;&#x7F16;&#x5199;&#x3001;&#x5F00;&#x53D1;&#x8C03;&#x8BD5;&#x66F4;&#x65B9;&#x4FBF;&#x3002;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">seajs.config({</div><div class="line">  <span class="comment">// &#x522B;&#x540D;&#x914D;&#x7F6E;</span></div><div class="line">  alias: {</div><div class="line">    <span class="string">&apos;es5-safe&apos;</span>: <span class="string">&apos;gallery/es5-safe/0.9.3/es5-safe&apos;</span>,</div><div class="line">    <span class="string">&apos;json&apos;</span>: <span class="string">&apos;gallery/json/1.0.2/json&apos;</span>,</div><div class="line">    <span class="string">&apos;jquery&apos;</span>: <span class="string">&apos;jquery/jquery/1.10.1/jquery&apos;</span></div><div class="line">  },</div><div class="line">  <span class="comment">// &#x8DEF;&#x5F84;&#x914D;&#x7F6E;</span></div><div class="line">  paths: {</div><div class="line">    <span class="string">&apos;gallery&apos;</span>: <span class="string">&apos;https://a.alipayobjects.com/gallery&apos;</span></div><div class="line">  },</div><div class="line">  <span class="comment">// Sea.js &#x7684;&#x57FA;&#x7840;&#x8DEF;&#x5F84;</span></div><div class="line">  base: <span class="string">&apos;http://example.com/path/to/base/&apos;</span>,</div><div class="line">});</div></pre></td></tr></table></figure>
<h3 id="&#x4F7F;&#x7528;-SeaJS-&#x5F00;&#x53D1;&#x8BA1;&#x7B97;&#x5668;&#x6848;&#x4F8B;"><a href="#&#x4F7F;&#x7528;-SeaJS-&#x5F00;&#x53D1;&#x8BA1;&#x7B97;&#x5668;&#x6848;&#x4F8B;" class="headerlink" title="&#x4F7F;&#x7528; SeaJS &#x5F00;&#x53D1;&#x8BA1;&#x7B97;&#x5668;&#x6848;&#x4F8B;"></a>&#x4F7F;&#x7528; SeaJS &#x5F00;&#x53D1;&#x8BA1;&#x7B97;&#x5668;&#x6848;&#x4F8B;</h3><ul>
<li>index.html</li>
</ul>
<figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div></pre></td><td class="code"><pre><div class="line"><span class="meta">&lt;!DOCTYPE html&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">title</span>&gt;</span>SeaJS - &#x8BA1;&#x7B97;&#x5668;&#x6848;&#x4F8B;<span class="tag">&lt;/<span class="name">title</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">id</span>=<span class="string">&quot;x&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">select</span> <span class="attr">name</span>=<span class="string">&quot;&quot;</span> <span class="attr">id</span>=<span class="string">&quot;opt&quot;</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">option</span> <span class="attr">value</span>=<span class="string">&quot;0&quot;</span>&gt;</span>+<span class="tag">&lt;/<span class="name">option</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">option</span> <span class="attr">value</span>=<span class="string">&quot;1&quot;</span>&gt;</span>-<span class="tag">&lt;/<span class="name">option</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">option</span> <span class="attr">value</span>=<span class="string">&quot;2&quot;</span>&gt;</span>*<span class="tag">&lt;/<span class="name">option</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">option</span> <span class="attr">value</span>=<span class="string">&quot;3&quot;</span>&gt;</span>/<span class="tag">&lt;/<span class="name">option</span>&gt;</span></div><div class="line">  <span class="tag">&lt;/<span class="name">select</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">id</span>=<span class="string">&quot;y&quot;</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">button</span> <span class="attr">id</span>=<span class="string">&quot;cal&quot;</span>&gt;</span>=<span class="tag">&lt;/<span class="name">button</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">id</span>=<span class="string">&quot;result&quot;</span>&gt;</span></div><div class="line">  <span class="comment">&lt;!-- </span></div><div class="line">    &#x6A21;&#x5757;&#x7CFB;&#x7EDF;&#xFF1A;</div><div class="line">      1. &#x5B9A;&#x4E49;&#x6A21;&#x5757;&#x6210;&#x5458;</div><div class="line">      2. &#x8BBE;&#x5B9A;&#x4EA4;&#x4E92;&#x89C4;&#x5219;</div><div class="line">    0. &#x5F15;&#x5305;</div><div class="line">    1. &#x4F7F;&#x7528; define &#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#xFF0C;&#x6240;&#x6709;&#x4EE3;&#x7801;&#x5199;&#x5230; define &#x56DE;&#x8C03;&#x51FD;&#x6570;&#x4E2D;</div><div class="line">    2. &#x4F7F;&#x7528; module.exports &#x4F5C;&#x4E3A;&#x6A21;&#x5757;&#x4E0E;&#x6A21;&#x5757;&#x4E4B;&#x95F4;&#x7684;&#x901A;&#x4FE1;&#x63A5;&#x53E3;&#x5BF9;&#x8C61;</div><div class="line">    3. &#x4F7F;&#x7528; requrie &#x51FD;&#x6570;&#x52A0;&#x8F7D;&#x6A21;&#x5757;&#xFF0C;&#x6267;&#x884C;&#x6A21;&#x5757;&#x4E2D;&#x7684;&#x4EE3;&#x7801;&#xFF0C;&#x5F97;&#x5230;&#x6A21;&#x5757;&#x4E2D;&#x7684; module.exports &#x63A5;&#x53E3;&#x5BF9;&#x8C61;</div><div class="line">    4. &#x4F7F;&#x7528; seajs.use &#x65B9;&#x6CD5;&#xFF0C;&#x542F;&#x52A8;&#x6A21;&#x5757;&#x7CFB;&#x7EDF;&#xFF0C;&#x7C7B;&#x4F3C;&#x4E8E;&#x7535;&#x8111;&#x5F00;&#x673A;</div><div class="line">   --&gt;</div><div class="line">  <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;../node_modules/seajs/dist/sea.js&quot;</span>&gt;</span><span class="undefined"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="javascript"></span></div><div class="line">    seajs.use(<span class="string">&apos;./js/main&apos;</span>)</div><div class="line">  <span class="tag">&lt;/<span class="name">script</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></div></pre></td></tr></table></figure>
<ul>
<li>main.js &#x6587;&#x4EF6;</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div></pre></td><td class="code"><pre><div class="line">define(<span class="function"><span class="keyword">function</span> (<span class="params">require, exports, module</span>) </span>{</div><div class="line">  <span class="keyword">var</span> $ = <span class="built_in">require</span>(<span class="string">&apos;../../node_modules/jquery/dist/jquery&apos;</span>);</div><div class="line">  <span class="comment">// &#x5982;&#x679C;&#x60F3;&#x8981;&#x62FF;&#x5230; jQuery &#x63A5;&#x53E3;&#x5BF9;&#x8C61;&#xFF0C;&#x90A3;&#x4E48; jquery.js &#x6587;&#x4EF6;&#x5185;&#x90E8;&#x5FC5;&#x987B;&#x663E;&#x793A;&#x7684;&#x901A;&#x8FC7; moudle.exports &#x5411;&#x5916;&#x66B4;&#x9732;</span></div><div class="line">  <span class="keyword">var</span> cal = <span class="built_in">require</span>(<span class="string">&apos;./cal/index&apos;</span>);</div><div class="line">  <span class="keyword">var</span> oX = <span class="built_in">document</span>.querySelector(<span class="string">&apos;#x&apos;</span>);</div><div class="line">  <span class="keyword">var</span> oOpt = <span class="built_in">document</span>.querySelector(<span class="string">&apos;#opt&apos;</span>);</div><div class="line">  <span class="keyword">var</span> oY = <span class="built_in">document</span>.querySelector(<span class="string">&apos;#y&apos;</span>);</div><div class="line">  <span class="keyword">var</span> oResult = <span class="built_in">document</span>.querySelector(<span class="string">&apos;#result&apos;</span>);</div><div class="line">  <span class="keyword">var</span> oCal = <span class="built_in">document</span>.querySelector(<span class="string">&apos;#cal&apos;</span>);</div><div class="line">  oCal.addEventListener(<span class="string">&apos;click&apos;</span>, <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>{</div><div class="line">    <span class="keyword">var</span> opt = oOpt.value;</div><div class="line">    <span class="keyword">var</span> result = <span class="number">0</span>;</div><div class="line">    <span class="keyword">var</span> x = oX.value;</div><div class="line">    <span class="keyword">var</span> y = oY.value;</div><div class="line">    <span class="keyword">switch</span> (opt) {</div><div class="line">      <span class="keyword">case</span> <span class="string">&apos;0&apos;</span>:</div><div class="line">        result = cal.add(x, y);</div><div class="line">        <span class="keyword">break</span>;</div><div class="line">      <span class="keyword">case</span> <span class="string">&apos;1&apos;</span>:</div><div class="line">        result = cal.sub(x, y);</div><div class="line">        <span class="keyword">break</span>;</div><div class="line">      <span class="keyword">case</span> <span class="string">&apos;2&apos;</span>:</div><div class="line">        result = cal.multiply(x, y);</div><div class="line">        <span class="keyword">break</span>;</div><div class="line">      <span class="keyword">case</span> <span class="string">&apos;3&apos;</span>:</div><div class="line">        result = cal.divide(x, y);</div><div class="line">        <span class="keyword">break</span>;</div><div class="line">    }</div><div class="line">    oResult.value = result;</div><div class="line">  });</div><div class="line">});</div></pre></td></tr></table></figure>
<ul>
<li>index.js</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line"> * &#x6BCF;&#x4E2A;&#x6587;&#x4EF6;&#x6A21;&#x5757;&#x4E2D;&#x9ED8;&#x8BA4;&#x5BF9;&#x5916;&#x7684;&#x63A5;&#x53E3;&#x5BF9;&#x8C61;&#x5C31;&#x662F; module.exports</div><div class="line"> * &#x540C;&#x65F6; SeaJS &#x8FD8;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#x5BF9;&#x8C61; exports</div><div class="line"> * &#x6CE8;&#x610F;&#xFF1A;exports &#x662F; module.exports &#x63A5;&#x53E3;&#x5BF9;&#x8C61;&#x7684;&#x4E00;&#x4E2A;&#x5F15;&#x7528;</div><div class="line"> *       &#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#xFF1A;&#x4FEE;&#x6539;&#x4E86; exports &#x76F8;&#x5F53;&#x4E8E;&#x4FEE;&#x6539;&#x4E86; module.exports</div><div class="line"> *       &#x4F46;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x60F3;&#x8981;&#x5411;&#x5916;&#x90E8;&#x66B4;&#x9732;&#x4E00;&#x4E2A;&#x5355;&#x72EC;&#x7684;&#x53D8;&#x91CF;&#x3001;&#x51FD;&#x6570;&#x7B49;&#x6210;&#x5458;&#xFF0C;</div><div class="line"> *       &#x90A3;&#x5C31;&#x5FC5;&#x987B;&#x901A;&#x8FC7;&#x7ED9; module.exports &#x8D4B;&#x503C;&#x624D;&#x53EF;&#x4EE5;</div><div class="line"> */</div><div class="line">define(<span class="function"><span class="keyword">function</span> (<span class="params">require, exports, module</span>) </span>{</div><div class="line">  exports.add = <span class="built_in">require</span>(<span class="string">&apos;./add&apos;</span>);</div><div class="line">  exports.sub = <span class="built_in">require</span>(<span class="string">&apos;./sub&apos;</span>);</div><div class="line">});</div></pre></td></tr></table></figure>
<ul>
<li>add.js</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">define(<span class="function"><span class="keyword">function</span> (<span class="params">require, exports, module</span>) </span>{</div><div class="line">  <span class="built_in">module</span>.exports = <span class="function"><span class="keyword">function</span> (<span class="params">x, y</span>) </span>{</div><div class="line">    <span class="keyword">return</span> <span class="built_in">parseFloat</span>(x) + <span class="built_in">parseFloat</span>(y);</div><div class="line">  }</div><div class="line">});</div></pre></td></tr></table></figure>
<ul>
<li>sub.js</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">define(<span class="function"><span class="keyword">function</span> (<span class="params">require, exports, module</span>) </span>{</div><div class="line">  <span class="built_in">module</span>.exports = <span class="function"><span class="keyword">function</span> (<span class="params">x, y</span>) </span>{</div><div class="line">    <span class="keyword">return</span> <span class="built_in">parseFloat</span>(x) - <span class="built_in">parseFloat</span>(y);</div><div class="line">  }</div><div class="line">});</div></pre></td></tr></table></figure>
<hr>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        
  <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
    <div>感谢您的支持！</div>
    <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
      <span>打 赏</span>
    </button>
    <div id="QR" style="display: none;">
      
        <div id="wechat" style="display: inline-block">
          <img id="wechat_qr" src="http://ofy7k3v4s.bkt.clouddn.com/wcpayCode.jpg" alt="Hongqin Ma WeChat Pay"/>
          <p>微信打赏</p>
        </div>
      
      
        <div id="alipay" style="display: inline-block">
          <img id="alipay_qr" src="http://ofy7k3v4s.bkt.clouddn.com/apayCode.jpg" alt="Hongqin Ma Alipay"/>
          <p>支付宝打赏</p>
        </div>
      
    </div>
  </div>


      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/模块化/" rel="tag">#模块化</a>
          
            <a href="/tags/SeaJs/" rel="tag">#SeaJs</a>
          
            <a href="/tags/RequireJS/" rel="tag">#RequireJS</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2015/04/03/t10-gulp-构建工具/" rel="next" title="Gulp 构建工具">
                <i class="fa fa-chevron-left"></i> Gulp 构建工具
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2015/06/18/26-AngularJS-框架/" rel="prev" title="AngularJS 框架">
                AngularJS 框架 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        <div class="ds-share flat" data-thread-key="2015/05/11/25-js-的模块化/"
     data-title="js 的模块化"
     data-content=""
     data-url="https://hongqinma.github.io/2015/05/11/25-js-的模块化/">
  <div class="ds-share-inline">
    <ul  class="ds-share-icons-16">

      <li data-toggle="ds-share-icons-more"><a class="ds-more" href="javascript:void(0);">分享到：</a></li>
      <li><a class="ds-weibo" href="javascript:void(0);" data-service="weibo">微博</a></li>
      <li><a class="ds-qzone" href="javascript:void(0);" data-service="qzone">QQ空间</a></li>
      <li><a class="ds-qqt" href="javascript:void(0);" data-service="qqt">腾讯微博</a></li>
      <li><a class="ds-wechat" href="javascript:void(0);" data-service="wechat">微信</a></li>

    </ul>
    <div class="ds-share-icons-more">
    </div>
  </div>
</div>
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2015/05/11/25-js-的模块化/"
           data-title="js 的模块化" data-url="https://hongqinma.github.io/2015/05/11/25-js-的模块化/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            Overview
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="//schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/photo.jpg"
               alt="Hongqin Ma" />
          <p class="site-author-name" itemprop="name">Hongqin Ma</p>
          <p class="site-description motion-element" itemprop="description">Spell at all costs， to rush you in the future. </p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">68</span>
              <span class="site-state-item-name">posts</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">16</span>
                <span class="site-state-item-name">categories</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">57</span>
                <span class="site-state-item-name">tags</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/HongqinMa" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://twitter.com/HongqinMa" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://www.facebook.com/profile.php?id=100006581058735" target="_blank" title="Facebook">
                  
                    <i class="fa fa-fw fa-facebook"></i>
                  
                  Facebook
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://www.zhihu.com/people/HirakuMa" target="_blank" title="知乎">
                  
                    <i class="fa fa-fw fa-share-alt"></i>
                  
                  知乎
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              Links
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/rubylouvre/" title="司徒正美" target="_blank">司徒正美</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/sanshi/" title="三生石上" target="_blank">三生石上</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/TomXu/" title="汤姆大叔" target="_blank">汤姆大叔</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://gold.xitu.io/" title="掘金" target="_blank">掘金</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://segmentfault.com/" title="segmentfault" target="_blank">segmentfault</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.jianshu.com/users/1cbb94e5ed4d/latest_articles" title="简书" target="_blank">简书</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://home.cnblogs.com/" title="博客园" target="_blank">博客园</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://www.awesomes.cn/" title="Awesomes" target="_blank">Awesomes</a>
                </li>
              
            </ul>
          </div>
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#JavaScript-模块化开发"><span class="nav-number">1.</span> <span class="nav-text">JavaScript 模块化开发</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#模块化介绍"><span class="nav-number">2.</span> <span class="nav-text">模块化介绍</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#模块化开发演变"><span class="nav-number">3.</span> <span class="nav-text">模块化开发演变</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#全局函数"><span class="nav-number">3.1.</span> <span class="nav-text">全局函数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#命名空间"><span class="nav-number">3.2.</span> <span class="nav-text">命名空间</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#私有空间"><span class="nav-number">3.3.</span> <span class="nav-text">私有空间</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#模块的维护和扩展"><span class="nav-number">3.4.</span> <span class="nav-text">模块的维护和扩展</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#模块的第三方依赖"><span class="nav-number">3.5.</span> <span class="nav-text">模块的第三方依赖</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#总结"><span class="nav-number">3.6.</span> <span class="nav-text">总结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#模块化规范"><span class="nav-number">4.</span> <span class="nav-text">模块化规范</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#模块系统理解"><span class="nav-number">4.1.</span> <span class="nav-text">模块系统理解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#常见的-JavaScript-模块化规范"><span class="nav-number">4.2.</span> <span class="nav-text">常见的 JavaScript 模块化规范</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#SeaJS"><span class="nav-number">5.</span> <span class="nav-text">SeaJS</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#SeaJS-介绍"><span class="nav-number">5.1.</span> <span class="nav-text">SeaJS 介绍</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#快速上手（Getting-Started）"><span class="nav-number">5.2.</span> <span class="nav-text">快速上手（Getting Started）</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#API-详解"><span class="nav-number">5.3.</span> <span class="nav-text">API 详解</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#seajs-use-加载模块-普通路径"><span class="nav-number">5.3.1.</span> <span class="nav-text">seajs.use 加载模块-普通路径</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#define-factory"><span class="nav-number">5.3.2.</span> <span class="nav-text">define(factory)</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#require-解决依赖"><span class="nav-number">5.3.3.</span> <span class="nav-text">require 解决依赖</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#模块标识"><span class="nav-number">5.3.4.</span> <span class="nav-text">模块标识</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#module"><span class="nav-number">5.3.5.</span> <span class="nav-text">module</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#exports"><span class="nav-number">5.3.6.</span> <span class="nav-text">exports</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#exports-和-module-exports-的区别"><span class="nav-number">5.4.</span> <span class="nav-text">exports 和 module.exports 的区别</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#如何将一个普通的模块文件改造为兼容-CMD-规范的模块"><span class="nav-number">5.5.</span> <span class="nav-text">如何将一个普通的模块文件改造为兼容 CMD 规范的模块</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#高级配置-seajs-config-options"><span class="nav-number">5.6.</span> <span class="nav-text">高级配置 seajs.config(options)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#使用-SeaJS-开发计算器案例"><span class="nav-number">5.7.</span> <span class="nav-text">使用 SeaJS 开发计算器案例</span></a></li></ol></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Hongqin Ma</span>
</div>

<div class="powered-by">
  Powered by <a class="theme-link" href="https://hexo.io">Hexo</a>
</div>

<div class="theme-info">
  Theme -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>

<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<span id="busuanzi_container_site_pv">
    &nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;Page Views: <span id="busuanzi_value_site_pv"></span> 
</span>

        

<div class="busuanzi-count">

  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv"><i class="fa fa-user"></i><span class="busuanzi-value" id="busuanzi_value_site_uv"></span></span>
  

  
    <span class="site-pv"><i class="fa fa-eye"></i><span class="busuanzi-value" id="busuanzi_value_site_pv"></span></span>
  
  
</div>



        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.2"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.2"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.2"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"Hiraku"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    <script src="/lib/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  






  
  

  

  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
  <script>AV.initialize("PPmoIQxeu8Sd21h6Tl9TthNx-gzGzoHsz", "rTvbY2H7DvWzRipiBwn72RQ4");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  
  
  <!-- custom analytics part create by xiamo -->
<script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
<script>AV.initialize("PPmoIQxeu8Sd21h6Tl9TthNx-gzGzoHsz", "rTvbY2H7DvWzRipiBwn72RQ4");</script>
<script>
function showTime(Counter) {
  var query = new AV.Query(Counter);
  $(".leancloud_visitors").each(function() {
    var url = $(this).attr("id").trim();
    query.equalTo("url", url);
    query.find({
      success: function(results) {
        if (results.length == 0) {
          var content = '0 ' + $(document.getElementById(url)).text();
          $(document.getElementById(url)).text(content);
          return;
        }
        for (var i = 0; i < results.length; i++) {
          var object = results[i];
          var content = object.get('time') + ' ' + $(document.getElementById(url)).text();
          $(document.getElementById(url)).text(content);
        }
      },
      error: function(object, error) {
        console.log("Error: " + error.code + " " + error.message);
      }
    });

  });
}

function addCount(Counter) {
  var Counter = AV.Object.extend("Counter");
  url = $(".leancloud_visitors").attr('id').trim();
  title = $(".leancloud_visitors").attr('data-flag-title').trim();
  var query = new AV.Query(Counter);
  query.equalTo("url", url);
  query.find({
    success: function(results) {
      if (results.length > 0) {
        var counter = results[0];
        counter.fetchWhenSave(true);
        counter.increment("time");
        counter.save(null, {
          success: function(counter) {
            var content =  counter.get('time') + ' ' + $(document.getElementById(url)).text();
            $(document.getElementById(url)).text(content);
          },
          error: function(counter, error) {
            console.log('Failed to save Visitor num, with error message: ' + error.message);
          }
        });
      } else {
        var newcounter = new Counter();
        newcounter.set("title", title);
        newcounter.set("url", url);
        newcounter.set("time", 1);
        newcounter.save(null, {
          success: function(newcounter) {
              console.log("newcounter.get('time')="+newcounter.get('time'));
            var content = newcounter.get('time') + ' ' + $(document.getElementById(url)).text();
            $(document.getElementById(url)).text(content);
          },
          error: function(newcounter, error) {
            console.log('Failed to create');
          }
        });
      }
    },
    error: function(error) {
      console.log('Error:' + error.code + " " + error.message);
    }
  });
}
$(function() {
  var Counter = AV.Object.extend("Counter");
  if ($('.leancloud_visitors').length == 1) {
    addCount(Counter);
  } else if ($('.post-title-link').length > 1) {
    showTime(Counter);
  }
}); 
</script>

  
</body>
</html>
